$(document).ready(function() {	
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventLevel.action",
  		success:function(data){
  			var elId=$("#elId").val();
  			$.each(data.eventLevels,function(i,n){
  				if(n.elId==elId)
  					$("<option value="+n.elId+" selected>"+n.elEventLevel+"</option>").appendTo("#eventLevel");
  				else
  					$("<option value="+n.elId+">"+n.elEventLevel+"</option>").appendTo("#eventLevel");
			});
  		}
	});
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventType.action",
  		success:function(data){
  			var etId=$("#etId").val();
  			$.each(data.eventTypes,function(i,n){
  				if(n.etId==etId)
  					$("<option value="+n.etId+" selected>"+n.etEventType+"</option>").appendTo("#eventType");
  				else
  					$("<option value="+n.etId+">"+n.etEventType+"</option>").appendTo("#eventType");
			});
  		}
	});
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventSource.action",
  		success:function(data){
  			var esId = $("#esId").val();
  			$.each(data.eventSources,function(i,n){
  				if(n.esId==esId)
  					$("<option value="+n.esId+" selected>"+n.esEventSource+"</option>").appendTo("#eventSource");
  				else
  					$("<option value="+n.esId+">"+n.esEventSource+"</option>").appendTo("#eventSource");
			});
  		}
	});
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventStatus.action",
  		success:function(data){
  			var tbesId=$("#tbesId").val();
  			$.each(data.eventStatuses,function(i,n){
  				if(n.tbesId==tbesId)
  					$("<option value="+n.tbesId+" selected>"+n.tbesEventStatus+"</option>").appendTo("#eventStatus");
  				else
  					$("<option value="+n.tbesId+">"+n.tbesEventStatus+"</option>").appendTo("#eventStatus");
			});
  		}
	});
	$('.num').numeric();
	$('.dou').numeric({allow:"."});
	$("#editForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单  
//			var strHTML="<div id='saving'><div id='s' class='faqbg'></div>";
//				strHTML+="<div id='su' class='loadingdiv' >";
//				strHTML+="<img src='wzp/images/loading.gif' />";
//				strHTML+="  正在更新事件....</div></div>"
//			$("body").append(strHTML);	
//			$("#s").css({display:"block",height:$(parent.document).height()});
//			parent.document.documentElement.scrollTop=0;
			var event={
				"event.EId":$('#EId').attr('value'),
				"event.tbEventStatus.tbesId":$('#eventStatus').attr('value'),
				"event.tbEventLevel.elId":$('#eventLevel').attr('value'),
				"event.tbEventSource.esId":$('#eventSource').attr('value'),
				"event.ESubmiterContact":$('#submitContact').attr('value'),
				//"event.ESubmitTime":$('#submitTime').attr('value'),
				"event.ESubmiter":$('#submiter').attr('value'),
				//"event.ESubmitDept":$('#submitDept').attr('value'),
				"event.tbUserByUId.UId":$('#user').attr('value'),
				"event.EEventAddr":$('#eventAddr').attr('value'),
				"event.ELongitude":$('#longitude').attr('value'),
				"event.ELatitude":$('#latitude').attr('value'),
				"event.EEventtime":$('#eventTime').attr('value'),
				"event.EEventname":$('#eventName').attr('value'),
				"event.tbEventType.etId":$('#eventType').attr('value'),
				"event.EDeaths":$('#death').attr('value'),
				"event.EInjuries":$('#injuries').attr('value'),
				"event.EEventCause":$('#eventCause').attr('value'),
				"event.EEventDesc":$('#eventDesc').attr('value'),
				"event.ETakeMeasure":$('#takeMeasure').attr('value')
			}
			if(confirm("确定要提交修改？")){
				$.ajax({
	  				type: "post",
	 				url: "wzp/event_update.action",
	 				data:event,
	  				success:function(data){
	  					if(data=="true"){
	  						alert("修改成功！")
	  						//parent.window.location.href="/ag/work/event_query_start.jsp";
	  						//alert("ddmmm");
	  						//window.location.replace("/ag/work/event_query_start.jsp");
	  						$('#tabFrame', window.parent.document).attr("src", "/ag/work/event_query_start.jsp");
	  					}else{
	  						alert("修改失败！")
	  					}
	  				}
				});
			}
        },
		rules: {
			'event.tbEventSource.esId':'required',
			'event.ESubmiter':{
				required:true,
				maxlength:10
			},
			'event.ESubmitDept':'required',
			'event.EEventAddr':{
				required:true,
				maxlength:50 
			},
			'event.ELongitude':{
				reuqierd:false,
				number: true,
				maxlength:20
			},
			'event.ELatitude':{
				reuqierd:false,
				number: true,
				maxlength:20
			},
			'event.tbEventType.etId':'required',
			eventTime:'required',
			'event.EEventname':{
				required:true,
				maxlength:30 
			},
			'event.EDeaths':{
				reuqierd:false,
				digits: true
			},
			'event.EInjuries':{
				reuqierd:false,
				digits: true
			},
			'event.ETrapped':{
				reuqierd:false,
				digits: true
			},
			'event.EMissing':{
				reuqierd:false,
				digits: true
			},
			'event.EEconomicLoss':{
				reuqierd:false,
				number: true
			},
			'event.tbEventLevel.elId':'required',
			'event.EEventCause':'required',
			'event.EEventDesc':'required'
		},
		messages: {
			'event.tbEventSource.esId':"*必须选",
			'event.ESubmiter':"*最多10个字",
			'event.ESubmitDept':"*",
			'event.EEventAddr':"*50字之内",
			'event.ELongitude':"最多20位数字" ,
			'event.ELatitude':"最多20位数字",
			'event.tbEventType.etId':"*必须选",
			eventTime:"*",
			'event.EEventname':"*30字之内",
			'event.EDeaths':"数字",
			'event.EInjuries':"数字",
			'event.ETrapped':"数字",
			'event.EMissing':"数字",
			'event.EEconomicLoss':"数字",
			'event.tbEventLevel.elId':"*必须选",
			'event.EEventCause':"*",
			'event.EEventDesc':"*"
		}
	});
	
});